using System.Collections.Generic;

namespace Dto
{
    public class MatchRoomDto
    {
        /*
         *  房间id
         */
        private int id;

        /**
         * 用户id <-> 用户实体
         */
        public Dictionary<string, Account> uids;

        /**
         * 准备玩家id
         */
        public List<string> readyUids;

        /**
         * 存储玩家进入的顺序
         */
        public List<string> uidList;
        
        
        public MatchRoomDto()
        {
            this.uids = new Dictionary<string, Account>();
            this.readyUids = new List<string>();
            //fix bug
            this.uidList = new List<string>();
        }

        public void AddUser(Account account)
        {
            uids.Add(account.id, account);
            uidList.Add(account.id);
        }

        public void RemoveUserById(string userId)
        {
            uids.Remove(userId);
            uidList.Remove(userId);
        }

        public void Ready(string userId)
        {
            readyUids.Add(userId);
        }

        /**
         * 代表左边玩家的id
         */
        public string LeftId;

        /**
         * 代表右边玩家的id
         */
        public string RightId;

        public void ResetPosition(string userId)
        {
            LeftId = null;
            RightId = null;
            if (uidList.Count == 1)
            {
              
            }
            else if (uidList.Count == 2)
            {
                if (uidList[0].Equals(userId))
                {
                    RightId = uidList[1];
                }

                if (uidList[1] == userId)
                {
                    LeftId = uidList[0];
                }
            }
            else if (uidList.Count == 3)
            {
                if (uidList[0] == userId)
                {
                    LeftId = uidList[2];
                    RightId = uidList[1];
                }
                if (uidList[1] == userId)
                {
                    LeftId = uidList[0];
                    RightId = uidList[2];
                }
                if (uidList[2] == userId)
                {
                    LeftId = uidList[1];
                    RightId = uidList[0];
                }
            }
        }
    }
}